package cn.lyf.service;


import cn.lyf.dao.UserDao;
import cn.lyf.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailsService implements UserDetailsService {
    @Autowired
    UserDao userDao;

    //username:浏览器登录的账号
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println("username=="+username);
        //根据username 获取数据库的user对象
        User u = userDao.findByUsername(username);
        System.out.println("u=="+u);
        //对从数据库获取到的密码进行加密
        return u;
    }
}
